package com.cuit.ocp.controller;

import com.cuit.ocp.bean.Trader;
import com.cuit.ocp.service.TraderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@CrossOrigin(origins ="*",maxAge = 3600)
@RestController
@RequestMapping("login")
public class LoginController {

    @Autowired
    public TraderService traderService;
    @GetMapping("check")
    public HashMap<Object,Object> check(Trader trader){
        System.out.println("@@@");
        HashMap<Object,Object> result = new HashMap<>();
        List<Trader> trader_info = traderService.findByName(trader.getTradername());
        if(trader_info.get(0) != null && trader_info.get(0).getPassword().equals(trader.getPassword()) == true ){
            result.put("message","success"); 
        }
        else{
            result.put("message","failure");
        }
        return result;
    }
}
